package com.atguigu.realtime.util;
    
    import org.wltea.analyzer.core.IKSegmenter;
    import org.wltea.analyzer.core.Lexeme;
    
    import java.io.IOException;
    import java.io.StringReader;
    import java.util.ArrayList;
    import java.util.List;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2021/2/16 20:54
 */
public class KeyWordUtil {
    public static List<String> analyze(String text) {
        final StringReader reader = new StringReader(text);
        final IKSegmenter ikSegmenter = new IKSegmenter(reader, true);
        final ArrayList<String> result = new ArrayList<>();
        try {
            Lexeme kw;
            while ((kw = ikSegmenter.next()) != null) {
                String lexemeText = kw.getLexemeText();
                result.add(lexemeText);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result;
    }
    
    public static void main(String[] args) {
        System.out.println(analyze("我是一个中国人"));
    }
}
